#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from enum import Enum, unique


@unique
class Gender(Enum):
    Male = 0
    Female = 1


class Student(object):
    def __init__(self, name, gender):
        if not isinstance(gender, Gender):
            raise TypeError("gender必须是Gender枚举类型")
        self.name = name
        self.gender = gender

    def __str__(self):
        return f"Student(name={self.name}, gender={self.gender.name})"


# 测试:
if __name__ == "__main__":
    try:
        bart = Student('Bart', Gender.Male)
        print(bart)  # 输出: Student(name=Bart, gender=Male)

        if bart.gender == Gender.Male:
            print('测试通过!')
        else:
            print('测试失败!')

        # 测试无效的性别类型
        invalid_student = Student('Lisa', 'Female')  # 这将引发TypeError
    except TypeError as e:
        print(f"错误: {e}")
